define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'classattr/classattr/index',
                    add_url: 'classattr/classattr/add',
                    edit_url: 'classattr/classattr/edit',
                    del_url: 'classattr/classattr/del',
                    multi_url: 'classattr/classattr/multi',
                    table: 'classattr',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'classnames.names', title: __('Classes_id')},
                        {field: 'names', title: __('Names')},
                       /* {field: 'sort', title: __('Sort')},*/
                        {field: 'is_show', title: __('Is_show') ,searchList:{1:__('Is_show 1'),2:__('Is_show 2')},visible:false},
                        {field: 'is_show_text', title: __('Is_show') ,operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange'},
                       /* {field: 'deletetime', title: __('Deletetime'), operate:'RANGE', addclass:'datetimerange'},*/
                        {field: 'operate', title: __('Operate'), table: table, buttons: [

                                {
                                    name: 'attrvalue',
                                    text: '查看规格值',
                                    title: '查看规格值',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'classattr/classattrvalue/index'
                                },
                                {
                                    name: 'attrvalue',
                                    text: '添加规格值',
                                    title: '添加规格值',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'classattr/classattrvalue/add'
                                }], events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        attrvalue: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});